const code = `import time
start = time.time()
import cvxpy as cp
import numpy as np
import pandas as pd

def solve(N_oneway=10, E_oneway=20, P_oneway=10, T_oneway_st=3, T_oneway_ed=13, Oneway_ini_SOC=0.1, Oneway_lea_SOC=0.8,
    N_twoway=10, E_twoway=20, P_twoway=12, T_twoway_st=3, T_oneway_ed=13, Twoway_ini_SOC=0.1, Twoway_lea_SOC=0.8):
    '''
    输入参数:
        N_oneway: 有序充电电动车数量, 默认值10
        E_oneway: 有序充电电动车电池容量, 默认值20
        P_oneway: 有序充电电动车充电最大功率, 默认值10
        T_oneway_st: 有序充电开始时间, 默认值3
        T_oneway_ed: 有序充电停止时间, 默认值13
        Oneway_ini_SOC: 有序充电电动车到站电量, 默认值0.1
        Oneway_lea_SOC: 有序充电电动车离站电量, 默认值0.8
        N_twoway: V2G电动车数量, 默认值10
        E_twoway: 有序充电电动车电池容量, 默认值20
        P_twoway: V2G电动车充电最大功率, 默认值12
        T_twoway_st: V2G开始时间, 默认值3
        T_oneway_ed: V2G停止时间, 默认值13
        Twoway_ini_SOC: V2G电动车到站电量, 默认值0.1
        Twoway_lea_SOC: V2G电动车离站电量, 默认值0.8
    
    返回结果:
                   [result             # 输出 总功率曲线
                    ESS_result,        # 输出 储能电池功率曲线
                    OneWay_result,     # 输出 有序充电功率曲线
                    TwoWay1_result,    # 输出 V2G功率曲线
                    L_1]               # 输出 负荷曲线
    '''
    ## excel file to numpy array
    L_1 = pd.read_excel('power_15min.xls', index_col=False, header=None)
    L_1 = np.array(L_1)
    L_1 = L_1[0]

    N = len(L_1)
    unit_array = np.ones(shape=(N))
    eff_charge = 0.9
    eff_discharge = 1/0.9
    r_power = 9.43
    r_energy = 0.0457
    t = 0.25
    Emax = 420
    Pmax = 250
    BES_Eini = Emax/2
    Emax1 = E_oneway*N_oneway
    Pmax1 = P_oneway*N_oneway

    Emax2 = E_twoway*N_twoway
    Pmax2 = P_twoway*N_twoway

    BES_Emin = np.zeros(shape=(N))
    BES_Emin[95] = 210
    BES_Emax = Emax*unit_array


    BES_Pmax = Pmax*unit_array
    BES_Pmin = -Pmax*unit_array

    OneWay_Emin = np.zeros(shape=(N))

    OneWay_Emin[T_oneway_ed*4-1] = Oneway_lea_SOC*E_oneway*N_oneway




    OneWay_Pmax = Pmax1*unit_array
    OneWay_Pmin = 0*unit_array
    OneWay_Eini = 0*E_oneway*N_oneway*unit_array
    OneWay_Eini[T_oneway_st*4-1] = Oneway_ini_SOC*E_oneway*N_oneway;

    TwoWay_Emin = np.zeros(shape=(N))
    TwoWay_Emin[T_twoway_ed*4-1] = Twoway_lea_SOC*E_twoway*N_twoway 

    TwoWay_Pmax = Pmax2*unit_array
    TwoWay_Pmin = -Pmax2*unit_array
    TwoWay_Eini = 0*E_twoway*N_twoway*unit_array
    TwoWay_Eini[T_twoway_st*4-1] = Twoway_ini_SOC*E_twoway*N_twoway

    DRL = 0
    DRH = 300*unit_array
    DRH[16*4-1:18*4-1] = 500
    DRH_increa = 5
    demand_incap = 1

    W1 = 10000
    W2 = 10000
    W3 = 10000
    c1 = 1/W1
    c2 = 1/W2
    c3 = 1/W3

    OneWay_Pmax[0:T_oneway_st-1] = 0
    OneWay_Pmin[0:T_oneway_st-1] = 0

    OneWay_Pmax[T_oneway_ed+1:95] = 0
    OneWay_Pmin[T_oneway_ed+1:95] = 0

    TwoWay_Pmax[0:T_twoway_st-1] = 0
    TwoWay_Pmin[0:T_twoway_st-1] = 0

    TwoWay_Pmax[T_twoway_ed+1:95] = 0
    TwoWay_Pmin[T_twoway_ed+1:95] = 0


    ## creating A matrix
    A = np.zeros(shape=(N,N))
    A[0][1] = 1
    for i in range(N):
        for j in range(N):
            if j<=i:
                A[i][j] = t
            else:
                A[i][j] = 0
    ## create variables
    P_inv_charge = cp.Variable((N))
    P_inv_discharge = cp.Variable((N))
    P_inv_charge1 = cp.Variable((N))
    P_inv_discharge1 = cp.Variable((N))
    P_inv_charge2 = cp.Variable((N))
    P_inv_discharge2 = cp.Variable((N))

    first_item = c1*cp.sum(cp.abs(-P_inv_discharge+P_inv_charge))
    second_item = c2*cp.sum(cp.abs(-P_inv_discharge1+P_inv_charge1))
    third_item = c3*cp.sum(cp.abs(-P_inv_discharge2+P_inv_charge2))
    fourth_item = r_power*cp.max(-P_inv_discharge+P_inv_charge-P_inv_discharge1
                                +P_inv_charge1-P_inv_discharge2+P_inv_charge2+L_1)
    fifth_item = 30*r_energy*t*cp.sum(-P_inv_discharge+P_inv_charge-P_inv_discharge1
                                    +P_inv_charge1-P_inv_discharge2+P_inv_charge2+L_1)
    ob = first_item+second_item+third_item+fourth_item+fifth_item

    ##BES
    bes_const_1 = A@(P_inv_charge*eff_charge-P_inv_discharge*eff_discharge)+BES_Eini*unit_array
    bes_const_2 = A@(P_inv_charge*eff_charge-P_inv_discharge*eff_discharge)+BES_Eini*unit_array-BES_Emax
    bes_const_3 = P_inv_charge-P_inv_discharge-BES_Pmin
    bes_const_4 = P_inv_charge-P_inv_discharge-BES_Pmax

    ##ONE WAY
    oneway_const_1 = A@(P_inv_charge1*eff_charge-P_inv_discharge1*eff_discharge)+OneWay_Eini
    oneway_const_2 = A@(P_inv_charge1*eff_charge-P_inv_discharge1*eff_discharge)+OneWay_Eini-Emax1*unit_array
    oneway_const_3 = P_inv_charge1-P_inv_discharge1-OneWay_Pmin
    oneway_const_4 = P_inv_charge1-P_inv_discharge1-OneWay_Pmax

    ##two-way charger
    twoway_const_1 = A@(P_inv_charge2*eff_charge-P_inv_discharge2*eff_discharge)+TwoWay_Eini
    twoway_const_2 = A@(P_inv_charge2*eff_charge-P_inv_discharge2*eff_discharge)+TwoWay_Eini-Emax2*unit_array
    twoway_const_3 = P_inv_charge2-P_inv_discharge2-TwoWay_Pmin
    twoway_const_4 =  P_inv_charge2-P_inv_discharge2-TwoWay_Pmax

    ##demand response
    dr_const_1 = -P_inv_discharge+P_inv_charge-P_inv_discharge1+P_inv_charge1-P_inv_discharge2+P_inv_charge2+L_1
    dr_const_2 = -P_inv_discharge+P_inv_charge-P_inv_discharge1+P_inv_charge1-P_inv_discharge2+P_inv_charge2+L_1
    ##solving
    prob = cp.Problem(cp.Minimize(ob), [
                                        OneWay_Emin<= oneway_const_1,
                                        oneway_const_2<=0*unit_array,
                                        0*unit_array<=oneway_const_3,
                                        oneway_const_4<=0*unit_array,
                                        TwoWay_Emin<=twoway_const_1,
                                        twoway_const_2<=0*unit_array,
                                        0*unit_array<=twoway_const_3,
                                        twoway_const_4<=0*unit_array,
                                        DRL*unit_array<=dr_const_1,
                                        dr_const_2<=DRH,
                                        0<=P_inv_charge,0<=P_inv_discharge,0<=P_inv_charge1,0<=P_inv_discharge1,0<=P_inv_charge2,0<=P_inv_discharge2,
                                        BES_Emin<= bes_const_1 ,
                                        bes_const_2<=0*unit_array,
                                        0*unit_array<=bes_const_3,
                                        bes_const_4<=0*unit_array])

    prob.solve()
    end = time.time()



    result = -P_inv_discharge.value+P_inv_charge.value-P_inv_discharge1.value+P_inv_charge1.value-P_inv_discharge2.value+P_inv_charge2.value+L_1

    ESS_result = -P_inv_discharge.value+P_inv_charge.value
    ##  ESS_result = np.ones(96)*2

    OneWay_result = -P_inv_discharge1.value+P_inv_charge1.value
    ##  OneWay_result = np.ones(96)*3

    TwoWay1_result = -P_inv_discharge2.value+P_inv_charge2.value
    ## TwoWay1_result = np.ones(96)*4
    ori_load = L_1

    #   TwoWay2_result = -P_inv_discharge22.value+P_inv_charge22.value
    ## TwoWay2_result = np.ones(96)*5

    all_result = np.array([result,  # 输出 总功率曲线
                    ESS_result,        # 输出 储能电池功率曲线
                    OneWay_result,   # 输出 有序充电功率曲线
                    TwoWay1_result,   # 输出 V2G功率曲线
                    L_1])              # 输出 负荷曲线

    print(end - start)
    return all_result`;

export default code